<?php

namespace api\libs\swoft;

use api\libs\swoft\core\SwoftCore;
use api\libs\swoft\ifc\SwoftClient;
use yii\helpers\Json;

class SwoftEvent extends SwoftClient
{
    public function getList($arr_request, $access_token) {
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() . 'web/events';
        $options[SwoftCore::SWOFT_QUERY_STRING] = array_merge($arr_request, ['token' => $access_token]);
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_GET;
        return $this->sendRequest($options);
    }
    
    public function getOne($id, $access_token) {
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() . 'web/events/' . urldecode($id);
        $options[SwoftCore::SWOFT_QUERY_STRING] = ['token' => $access_token];
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_GET;
        return $this->sendRequest($options);
    }

    public function patch($id, $data, $access_token) {
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() .  'web/events/' . urldecode($id);
        $options[SwoftCore::SWOFT_QUERY_STRING] = ['token' => $access_token];
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_PATCH;
        $options[SwoftCore::SWOFT_CONTENT_TYPE] = 'application/json';
        $options[SwoftCore::SWOFT_CONTENT] = json_encode(['data' => $data]);
        return $this->sendRequest($options);
    }
    
    public function reportHandle($data, $access_token) {        
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() . 'app/event/report-handle';
        $options[SwoftCore::SWOFT_QUERY_STRING] = array('token' => $access_token);
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_POST;
        $options[SwoftCore::SWOFT_CONTENT_TYPE] = 'application/x-www-form-urlencoded';
        $options[SwoftCore::SWOFT_CONTENT] = http_build_query($this->convertParams($data));
        return $this->sendRequest($options);
    }
    
      public function reportMessage($data, $access_token) {        
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() . 'web/events/report-message';
        $options[SwoftCore::SWOFT_QUERY_STRING] = array('token' => $access_token);
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_POST;
        $options[SwoftCore::SWOFT_CONTENT_TYPE] = 'application/x-www-form-urlencoded';
        $options[SwoftCore::SWOFT_CONTENT] = http_build_query($this->convertParams($data));
        return $this->sendRequest($options);
    }
    
     public function update($id, $data, $access_token) {
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() .  'web/events/' . urldecode($id);
        $options[SwoftCore::SWOFT_QUERY_STRING] = ['token' => $access_token];
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_PUT;
        $options[SwoftCore::SWOFT_CONTENT_TYPE] = 'application/json';
        $options[SwoftCore::SWOFT_CONTENT] = json_encode(['data' => $data]);
        return $this->sendRequest($options);
    }
    
    
    public function reportMessageTask($data) {
        $options[SwoftCore::SWOFT_RESOURCE] = 'open-api/report-message';
        $options[SwoftCore::SWOFT_HEADERS] = array('token' => \Yii::$app->params['swoft_api']['token'],'appid'=>\Yii::$app->params['swoft_api']['appid']);
        $options[SwoftCore::SWOFT_QUERY_STRING] = [];
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_POST;
        $options[SwoftCore::SWOFT_CONTENT_TYPE] = 'application/x-www-form-urlencoded';
        $options[SwoftCore::SWOFT_CONTENT] = http_build_query($this->convertParams($data));
        return $this->sendRequest($options);
    }
}